package com.shijie.controller.app;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shijie.core.Result;
import com.shijie.core.ResultGenerator;
import com.shijie.domain.entity.Activitys;
import com.shijie.domain.entity.Recommends;
import com.shijie.domain.entity.UserScores;
import com.shijie.domain.enums.EnumInterface;
import com.shijie.service.ActivitysService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/*
 *  专题活动相关接口
 *
 *  @author: smart boy
 *  @date: 2018-08-06
 */
@RestController
@RequestMapping("/app/activitys")
public class AppActivitysController {

	@Resource
	private ActivitysService activitysService;

	@GetMapping
	public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "5") Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        Condition condition = new Condition(Activitys.class);
        Example.Criteria criteria = condition.createCriteria();
        criteria.andLessThanOrEqualTo("startDate", new Date());
        criteria.andGreaterThanOrEqualTo("endDate", new Date());
        condition.orderBy("id").desc();
        List<Activitys> list = activitysService.selectByCondition(condition);
        PageInfo<Activitys> pageInfo = new PageInfo<>(list);
        return ResultGenerator.success(pageInfo);
    }

}

